package com.aaa.controller;

import com.aaa.entity.Users;
import com.aaa.service.IUsersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RequestMapping("/admin")
@Controller
public class AdminLoginController {
    @RequestMapping("login_show")
    public String login(){
        return "/admin/login";
    }


    @Resource
    private IUsersService usersService;

    @RequestMapping("/login_submit")
    public String login_submit(Users users, HttpSession session, Model model) {
        Users u = usersService.adminLogin(users);
        System.out.println(u);
        if (u == null) {
            model.addAttribute("err", "用户名或密码不正确");
            return "/admin/login";
        }

        session.setAttribute("adminUser", u);
        return "/admin/index";
    }
}
